@extends('admin/common')

@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i>
        {{ $now_nav[0]['name'] }} <span class="c-gray en">&gt;</span>
        {{ $now_nav[1]['name'] }}
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
                <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
                <a href="javascript:;" onclick="admin_permission_add('添加权限节点','{{ URL::to('admin/permission/addPermission') }}','800')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加权限节点</a></span>
        </div>
        <table class="table table-border table-bordered table-bg" id="permissionTable">
            <thead>
            <tr>
                <th><input type="checkbox" name="" value=""></th>
                <th>ID</th>
                <th>权限名称</th>
                <th>权限规则</th>
                <th>权限描述</th>
                <th>是否菜单</th>
                <th>父级</th>
                <th>icon</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
    </div>
    @endsection

@section('script')
    <script type="text/javascript" src="{{ asset('admin/lib/datatables/1.10.0/jquery.dataTables.min.js') }}"></script>
    <script type="text/javascript">
        $(function(){
            //数据表格
            var dataTable = $("#permissionTable").dataTable({
                //配置
                "bServerSide": true,   //开启服务器数据
                "bSort": true,         //开启排序
                "sAjaxSource": "{{ URL::to('admin/permission/indexPost') }}",
                //服务器端，数据回调处理
                "fnServerData" : function(url, aDataSet, fnCallback) {
                    $.ajax({
                        "url" : url,
                        "dataType" : 'json',
                        "type" : "POST",
                        "data" : aDataSet,
                        "success" : fnCallback
                    });
                },
                //分页数据条数
                "iDisplayLength": 30,
                //排序
                "aaSorting": [
                    [1, 'asc']
                ],
                //语言
                "oLanguage": {
                    "sProcessing": "正在加载中...",
                    "sLengthMenu": "每页显示 _MENU_ 条记录",
                    "sZeroRecords": "抱歉, 没有匹配的数据",
                    "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                    "sInfoEmpty": "没有数据",
                    "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                    "sSearch": "搜索",
                    "sLengthMenu": "_MENU_ 页/条",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上一页",
                        "sNext": "下一页",
                        "sLast": "尾页"
                    },
                    "sZeroRecords": "没有检索到数据"
                },
                //数据项
                "aoColumns": [
                    { "data": "id" ,"bSortable": false},
                    { "data": "id" },
                    { "data": "name", "bSortable": false },
                    { "data": "rule", "bSortable": false },
                    { "data": "description", "bSortable": false },
                    { "data": "is_menu", "bSortable": false },
                    { "data": "pid" ,"bSortable": false},
                    { "data": "icon" ,"bSortable": false},
                    { "data": "id", "bSortable": false }
                ],
                //自定义数据项
                'columnDefs' : [
                    {
                        "render" : function(data, type, row){
                            return '<input type="checkbox" value="'+data+'" name="ids">';
                        },
                        "targets" : 0
                    },
                    {
                        "render" : function(data, type, row){
                            return '<a title="编辑" href="javascript:;" onclick="admin_permission_edit(\'编辑\','+data+',\'800\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="admin_permission_del(this,'+data+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                        },
                        "targets" : 8
                    }
                ]
            });

        });

        /*
         参数解释：
         title	标题
         url		请求的url
         id		需要操作的数据id
         w		弹出层宽度（缺省调默认值）
         h		弹出层高度（缺省调默认值）
         */
        /*管理员-权限-添加*/
        function admin_permission_add(title,url,w,h){
            layer_show(title,url,w,h);
        }
        /*管理员-权限-编辑*/
        function admin_permission_edit(title,id,w,h){
            var url = "{{ URL::to('admin/permission/editPermission') }}"+'/'+id;
            layer_show(title,url,w,h);
        }

        /*管理员-权限-删除*/
        function admin_permission_del(obj,id){
            layer.confirm('确认要删除吗？',function(index){
                $.ajax({
                    type: 'POST',
                    url: '{{ URL::to('admin/permission/delPermissionPost') }}',
                    data : {
                       id : id
                    },
                    dataType: 'json',
                    success: function(ret){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    },
                    error:function(data) {
                        console.log(data.msg);
                    }
                });
            });
        }
    </script>
    @endsection